package com.ruoyi.zsyh.controller;

import java.util.List;

import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.EmptyUtils;
import com.ruoyi.zsyh.domain.ZsyhFactoryPayrel;
import com.ruoyi.zsyh.service.IZsyhFactoryPayrelService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zsyh.domain.ZsyhFactoryPay;
import com.ruoyi.zsyh.service.IZsyhFactoryPayService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 厂家服务费管理Controller
 * 
 * @author yuexl
 * @date 2021-12-24
 */
@Controller
@RequestMapping("/zsyh/factoryPay")
public class ZsyhFactoryPayController extends BaseController
{
    private String prefix = "zsyh/factoryPay";

    @Autowired
    private IZsyhFactoryPayService zsyhFactoryPayService;
    @Autowired
    private IZsyhFactoryPayrelService zsyhFactoryPayrelService;

    @RequiresPermissions("zsyh:factoryPay:view")
    @GetMapping()
    public String factoryPay()
    {
        return prefix + "/factoryPay";
    }

    /**
     * 查询厂家服务费管理列表
     */
    @RequiresPermissions("zsyh:factoryPay:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZsyhFactoryPay zsyhFactoryPay)
    {
        startPage();
        if(EmptyUtils.isEmpty(zsyhFactoryPay.getPeriodYear()) && EmptyUtils.isEmpty(zsyhFactoryPay.getPeriodMonth())){
            zsyhFactoryPay.setPeriodYear(DateUtils.getYear());
            zsyhFactoryPay.setPeriodMonth(DateUtils.getMonth());
        }
        List<ZsyhFactoryPay> list = zsyhFactoryPayService.selectZsyhFactoryPayList(zsyhFactoryPay);
        return getDataTable(list);
    }

    /**
     * 查询厂家服务费管理列表
     */
    @RequiresPermissions("zsyh:factoryPay:list")
    @PostMapping("/listChild")
    @ResponseBody
    public TableDataInfo listChild(String mid)
    {
        startPage();
        ZsyhFactoryPayrel zsyhFactoryPayrel = new ZsyhFactoryPayrel();
        zsyhFactoryPayrel.setPayId(mid);
        List<ZsyhFactoryPayrel> zsyhFactoryPayrelList = zsyhFactoryPayrelService.selectZsyhFactoryPayrelList(zsyhFactoryPayrel);
        return getDataTable(zsyhFactoryPayrelList);
    }

    /**
     * 导出厂家服务费管理列表
     */
    @RequiresPermissions("zsyh:factoryPay:export")
    @Log(title = "厂家服务费管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZsyhFactoryPay zsyhFactoryPay)
    {
        List<ZsyhFactoryPay> list = zsyhFactoryPayService.selectZsyhFactoryPayList(zsyhFactoryPay);
        ExcelUtil<ZsyhFactoryPay> util = new ExcelUtil<ZsyhFactoryPay>(ZsyhFactoryPay.class);
        return util.exportExcel(list, "厂家服务费管理数据");
    }

    /**
     * 新增厂家服务费管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存厂家服务费管理
     */
    @RepeatSubmit
    @RequiresPermissions("zsyh:factoryPay:add")
    @Log(title = "厂家服务费管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZsyhFactoryPay zsyhFactoryPay)
    {
        return toAjax(zsyhFactoryPayService.insertZsyhFactoryPay(zsyhFactoryPay));
    }

    /**
     * 修改厂家服务费管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhFactoryPay zsyhFactoryPay = zsyhFactoryPayService.selectZsyhFactoryPayById(id);
        mmap.put("zsyhFactoryPay", zsyhFactoryPay);
        return prefix + "/edit";
    }


    /**
     * 查看费用详细
     */
    @GetMapping("/viewDetail")
    public String viewDetail(String factoryId,String periodYear,String periodMonth, ModelMap mmap)
    {
        mmap.put("factoryId", factoryId);
        mmap.put("periodYear", periodYear);
        mmap.put("periodMonth", periodMonth);
        return prefix + "/viewDetail";
    }

    /**
     * 修改保存厂家服务费管理
     */
    @RepeatSubmit
    @RequiresPermissions("zsyh:factoryPay:edit")
    @Log(title = "厂家服务费管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZsyhFactoryPay zsyhFactoryPay)
    {
        return toAjax(zsyhFactoryPayService.updateZsyhFactoryPay(zsyhFactoryPay));
    }

    /**
     * 删除厂家服务费管理
     */
    @RepeatSubmit
    @RequiresPermissions("zsyh:factoryPay:remove")
    @Log(title = "厂家服务费管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zsyhFactoryPayService.deleteZsyhFactoryPayByIds(ids));
    }
}
